<!DOCTYPE html>


  <html class="dark page-post">


<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>Taro开发小程序体验 | Poetry&#39;s Blog</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="Taro,小程序,">
  

  <meta name="description" content="一、初识Taro1.1 优点 小程序中无法使用 npm 来进行第三方库的管理，无法使用一些比较新的 ES 规范等等，针对小程序端的开发弊端，Taro 具有以下的优秀特性   支持使用 npm/yarn 安装管理第三方依赖。 支持使用 ES7/ES8 甚至更加新的 ES 规范，一切都可自行配置 支持使用 CSS 预编译器，例如 Sass 等 支持使用 Redux 进行状态管理 小程序 API 优化，">
<meta name="keywords" content="Taro,小程序">
<meta property="og:type" content="article">
<meta property="og:title" content="Taro开发小程序体验">
<meta property="og:url" content="http://blog.poetries.top/2018/09/03/wx-taro/index.html">
<meta property="og:site_name" content="Poetry&#39;s Blog">
<meta property="og:description" content="一、初识Taro1.1 优点 小程序中无法使用 npm 来进行第三方库的管理，无法使用一些比较新的 ES 规范等等，针对小程序端的开发弊端，Taro 具有以下的优秀特性   支持使用 npm/yarn 安装管理第三方依赖。 支持使用 ES7/ES8 甚至更加新的 ES 规范，一切都可自行配置 支持使用 CSS 预编译器，例如 Sass 等 支持使用 Redux 进行状态管理 小程序 API 优化，">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2020-08-15T04:25:31.942Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Taro开发小程序体验">
<meta name="twitter:description" content="一、初识Taro1.1 优点 小程序中无法使用 npm 来进行第三方库的管理，无法使用一些比较新的 ES 规范等等，针对小程序端的开发弊端，Taro 具有以下的优秀特性   支持使用 npm/yarn 安装管理第三方依赖。 支持使用 ES7/ES8 甚至更加新的 ES 规范，一切都可自行配置 支持使用 CSS 预编译器，例如 Sass 等 支持使用 Redux 进行状态管理 小程序 API 优化，">

  

  
    <link rel="icon" href="/favicon.ico">
  

  <link href="/css/styles.css?v=c114cbeddx" rel="stylesheet">
<link href="/css/other.css?v=c114cbeddx" rel="stylesheet">


  
    <link rel="stylesheet" href="/css/personal-style.css">
  

  

  
  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?40b1f89aa80f2527b3db779c6898c879";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>


  
  <script type="text/javascript">
	(function(){
	    var bp = document.createElement('script');
	    var curProtocol = window.location.protocol.split(':')[0];
	    if (curProtocol === 'https') {
	        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
	    }
	    else {
	        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
	    }
	    var s = document.getElementsByTagName("script")[0];
	    s.parentNode.insertBefore(bp, s);
	})();
  </script>



  
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css">
  

  <!-- 聊天系统 -->
  
    
   <link type="text/css" rel="stylesheet" href="/renxi/default.css">
   <style>
      #modal {
        position: static !important;
      }
      .filter {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background: #fe5757;
        animation: colorChange 30s ease-in-out infinite;
        animation-fill-mode: both;
        mix-blend-mode: overlay;
      }
  
      @keyframes colorChange {
        0%, 100% {
            opacity: 0;
        }
        50% {
            opacity: .9;
        }
      }
   </style>
</head>
</html>
<body>
  
  
    <span id="toolbox-mobile" class="toolbox-mobile">导航</span>
  

  <div class="post-header CENTER">
   
  <div class="toolbox">
    <a class="toolbox-entry" href="/">
      <span class="toolbox-entry-text">导航</span>
      <i class="icon-angle-down"></i>
      <i class="icon-home"></i>
    </a>
    <ul class="list-toolbox">
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/archives/"
            rel="noopener noreferrer"
            target="_self"
            >
            博客
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/categories/"
            rel="noopener noreferrer"
            target="_self"
            >
            分类
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/tags/"
            rel="noopener noreferrer"
            target="_self"
            >
            标签
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/search/"
            rel="noopener noreferrer"
            target="_self"
            >
            搜索
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/link/"
            rel="noopener noreferrer"
            target="_self"
            >
            友链
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/about/"
            rel="noopener noreferrer"
            target="_self"
            >
            关于
          </a>
        </li>
      
    </ul>
  </div>


</div>


  <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录<i class="iconfont toc-title" style="display:inline-block;color:#87998d;width:20px;height:20px;">&#xf004b;</i></strong>
    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#一、初识Taro"><span class="toc-text">一、初识Taro</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-优点"><span class="toc-text">1.1 优点</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-快速开始"><span class="toc-text">1.2 快速开始</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-3-语法风格"><span class="toc-text">1.3 语法风格</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#二、生命周期函数"><span class="toc-text">二、生命周期函数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#三、路由"><span class="toc-text">三、路由</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#四、专属的方法"><span class="toc-text">四、专属的方法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#五、更多参考"><span class="toc-text">五、更多参考</span></a></li></ol>
  </div>
  




<div class="content content-post CENTER">
   <!-- canvas 彩带 -->
<canvas id="evanyou" width="1302" height="678" style="position: fixed;width: 100%;height: 100%;top: 0;left:0;z-index:-1;"></canvas>

<article id="post-wx-taro" class="article article-type-post" itemprop="blogPost">
  <header class="article-header" style="position:relative;">
    <h1 class="post-title">Taro开发小程序体验</h1>

    <div class="article-meta">
      <span>
        <i class="icon-calendar"></i>
        <span>2018.09.03</span>
      </span>

      
        <span class="article-author">
          <i class="icon-user"></i>
          <span>Poetry</span>
        </span>
      

      
  <span class="article-category">
    <i class="icon-list"></i>
    <a class="article-category-link" href="/categories/Front-End/">Front-End</a>
  </span>



      

      
      <i class="fa fa-eye"></i> 
        <span id="busuanzi_container_page_pv">
           &nbsp热度 <span id="busuanzi_value_page_pv">
           <i class="fa fa-spinner fa-spin"></i></span>℃
        </span>
      
      
       
          <span class="post-count">
            <i class="fa fa-file-word-o"></i>&nbsp
            <span>字数统计 1.4k字</span>
          </span>

          <span class="post-count">
            <i class="fa fa-columns"></i>&nbsp
            <span>阅读时长 5分</span>
          </span>
      
      
    </div>

    <i class="iconfont" id="toc-eye" style="display:inline-block;color:#b36619;position:absolute;top:0;right:0;cursor:pointer;
    font-size: 24px;">&#xe61c;</i>

  </header>

  <div class="article-content">
    
      <div id="container">
        <h2 id="一、初识Taro"><a href="#一、初识Taro" class="headerlink" title="一、初识Taro"></a>一、初识Taro</h2><h3 id="1-1-优点"><a href="#1-1-优点" class="headerlink" title="1.1 优点"></a>1.1 优点</h3><blockquote>
<p>小程序中无法使用 <code>npm</code> 来进行第三方库的管理，无法使用一些比较新的 <code>ES</code> 规范等等，针对小程序端的开发弊端，<code>Taro</code> 具有以下的优秀特性</p>
</blockquote>
<ul>
<li>支持使用 <code>npm/yarn</code> 安装管理第三方依赖。</li>
<li>支持使用 <code>ES7/ES8</code> 甚至更加新的 <code>ES</code> 规范，一切都可自行配置</li>
<li>支持使用 <code>CSS</code> 预编译器，例如 <code>Sass</code> 等</li>
<li>支持使用 <code>Redux</code> 进行状态管理</li>
<li>小程序 <code>API</code> 优化，异步 <code>API Promise</code> 化等</li>
</ul>
<h3 id="1-2-快速开始"><a href="#1-2-快速开始" class="headerlink" title="1.2 快速开始"></a>1.2 快速开始</h3><blockquote>
<p>微信小程序编译预览模式</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"># npm script</span><br><span class="line">$ npm run dev:weapp</span><br><span class="line"># 仅限全局安装</span><br><span class="line">$ taro build --type weapp --watch</span><br><span class="line"># npx用户也可以使用</span><br><span class="line">$ npx taro build --type weapp --watch</span><br></pre></td></tr></table></figure>
<blockquote>
<p>H5 编译预览模式</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"># npm script</span><br><span class="line">$ npm run dev:h5</span><br><span class="line"># 仅限全局安装</span><br><span class="line">$ taro build --type h5 --watch</span><br><span class="line"># npx用户也可以使用</span><br><span class="line">$ npx taro build --type h5 --watch</span><br></pre></td></tr></table></figure>
<blockquote>
<p>RN 编译预览模式</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"># npm script</span><br><span class="line">$ npm run dev:rn</span><br><span class="line"># 仅限全局安装</span><br><span class="line">$ taro build --type rn --watch</span><br><span class="line"># npx用户也可以使用</span><br><span class="line">$ npx taro build --type rn --watch</span><br></pre></td></tr></table></figure>
<p><strong>目录结构</strong></p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">├── dist                   编译结果目录</span><br><span class="line">├── config                 配置目录</span><br><span class="line">|   ├── dev.js             开发时配置</span><br><span class="line">|   ├── index.js           默认配置</span><br><span class="line">|   └── prod.js            打包时配置</span><br><span class="line">├── src                    源码目录</span><br><span class="line">|   ├── pages              页面文件目录</span><br><span class="line">|   |   ├── index          index页面目录</span><br><span class="line">|   |   |   ├── index.js   index页面逻辑</span><br><span class="line">|   |   |   └── index.css  index页面样式</span><br><span class="line">|   ├── app.css            项目总通用样式</span><br><span class="line">|   └── app.js             项目入口文件</span><br><span class="line">└── package.json</span><br></pre></td></tr></table></figure>
<blockquote>
<p>进入项目目录开始开发，可以选择小程序预览模式，或者h5预览模式，若使用微信小程序预览模式，则需要自行下载并打开微信开发者工具，选择预览项目根目录</p>
</blockquote>
<p><strong>注意</strong></p>
<ul>
<li>需要设置关闭<code>ES6</code>转<code>ES5</code>功能，开启可能报错</li>
<li>需要设置关闭上传代码时样式自动补全，开启可能报错</li>
<li>需要设置关闭代码压缩上传，开启可能报错</li>
</ul>
<h3 id="1-3-语法风格"><a href="#1-3-语法风格" class="headerlink" title="1.3 语法风格"></a>1.3 语法风格</h3><blockquote>
<p>Taro 的语法规则基于 <code>React</code> 规范，它采用与 <code>React</code> 一致的组件化思想，组件生命周期与 <code>React</code> 保持一致，同时在书写体验上也尽量与 <code>React</code> 类似，支持使用 <code>JSX</code> 语法</p>
</blockquote>
<blockquote>
<p>一个普通的入口文件示例如下<code>app.js</code></p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> Taro, &#123; Component &#125; <span class="keyword">from</span> <span class="string">'@tarojs/taro'</span></span><br><span class="line"><span class="keyword">import</span> Index <span class="keyword">from</span> <span class="string">'./pages/index'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'./app.scss'</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">App</span> <span class="keyword">extends</span> <span class="title">Component</span> </span>&#123;</span><br><span class="line">  <span class="comment">// 项目配置</span></span><br><span class="line">  config = &#123;</span><br><span class="line">    pages: [</span><br><span class="line">      <span class="string">'pages/index/index'</span></span><br><span class="line">    ],</span><br><span class="line">    <span class="built_in">window</span>: &#123;</span><br><span class="line">      backgroundTextStyle: <span class="string">'light'</span>,</span><br><span class="line">      navigationBarBackgroundColor: <span class="string">'#fff'</span>,</span><br><span class="line">      navigationBarTitleText: <span class="string">'WeChat'</span>,</span><br><span class="line">      navigationBarTextStyle: <span class="string">'black'</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  componentWillMount () &#123;&#125;</span><br><span class="line"></span><br><span class="line">  componentDidMount () &#123;&#125;</span><br><span class="line"></span><br><span class="line">  componentDidShow () &#123;&#125;</span><br><span class="line"></span><br><span class="line">  componentDidHide () &#123;&#125;</span><br><span class="line"></span><br><span class="line">  render () &#123;</span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">      &lt;Index /&gt;</span><br><span class="line">    )</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="二、生命周期函数"><a href="#二、生命周期函数" class="headerlink" title="二、生命周期函数"></a>二、生命周期函数</h2><p><strong>App.js生命周期</strong></p>
<table>
<thead>
<tr>
<th>生命周期方法</th>
<th>作用</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>componentWillMount</code></td>
<td>程序被载入</td>
<td>对应微信小程序<code>onLaunch</code></td>
</tr>
<tr>
<td><code>componentDidMount</code></td>
<td>程序被载入</td>
<td>对应微信小程序<code>onLaunch</code>，在<code>componentWillMount</code>之后执行</td>
</tr>
<tr>
<td><code>componentDidShow</code></td>
<td>程序展示出来</td>
<td>对应微信小程序<code>onShow</code></td>
</tr>
<tr>
<td><code>componentDidHide</code></td>
<td>程序被隐藏</td>
<td>对应微信小程序onHide</td>
</tr>
</tbody>
</table>
<blockquote>
<p>不过当然也包含<code>componentWillUnmout</code>和<code>componentWillReceiveProps</code>等<code>react</code>原始生命周期函数，用来编写自定义组件</p>
</blockquote>
<p><strong>页面生命周期</strong></p>
<table>
<thead>
<tr>
<th>生命周期方法</th>
<th>作用</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>componentWillMount</code></td>
<td>页面被载入</td>
<td>在微信小程序中这一生命周期方法对应 <code>onLoad</code></td>
</tr>
<tr>
<td><code>componentDidMount</code></td>
<td>页面渲染完成</td>
<td>在微信小程序中这一生命周期方法对应 <code>onReady</code></td>
</tr>
<tr>
<td><code>shouldComponentUpdate</code></td>
<td>页面是否需要更新</td>
<td></td>
</tr>
<tr>
<td><code>componentWillUpdate</code></td>
<td>页面即将更新</td>
<td></td>
</tr>
<tr>
<td><code>componentDidUpdate</code></td>
<td>页面更新完毕</td>
<td></td>
</tr>
<tr>
<td><code>componentWillUnmount</code></td>
<td>页面退出</td>
<td>在微信小程序中这一生命周期方法对应 <code>onUnload</code></td>
</tr>
<tr>
<td><code>componentDidShow</code></td>
<td>页面展示出来</td>
<td>在微信小程序中这一生命周期方法对应<code>onShow</code>，在<code>H5</code>中同样实现</td>
</tr>
<tr>
<td><code>componentDidHide</code></td>
<td>页面被隐藏</td>
<td>在微信小程序中这一生命周期方法对应 <code>onHide</code>，在<code>H5</code>中同样实现</td>
</tr>
</tbody>
</table>
<blockquote>
<p>微信小程序中 <code>onLoad</code> 通常带有一个参数 <code>options</code>，在 <code>Taro</code> 中你可以在所有生命周期方法中通过 <code>this.$router.params</code>访问到，在其他端也适用</p>
</blockquote>
<h2 id="三、路由"><a href="#三、路由" class="headerlink" title="三、路由"></a>三、路由</h2><blockquote>
<p>我们只需要在入口文件的 <code>config</code>配置中指定好 <code>pages</code>，然后就可以在代码中通过<code>Taro</code> 提供的 API 来跳转到目的页面，例如</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 跳转到目的页面，打开新页面</span></span><br><span class="line">Taro.navigateTo(&#123;</span><br><span class="line">  url: <span class="string">'/pages/page/path/name'</span></span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">// 跳转到目的页面，在当前页面打开</span></span><br><span class="line">Taro.redirectTo(&#123;</span><br><span class="line">  url: <span class="string">'/pages/page/path/name'</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<p><strong>传参</strong></p>
<blockquote>
<p>我们可以通过在所有跳转的 url 后面添加查询字符串参数进行跳转传参，例如</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 传入参数 id=2&amp;type=test</span></span><br><span class="line">Taro.navigateTo(&#123;</span><br><span class="line">  url: <span class="string">'/pages/page/path/name?id=2&amp;type=test'</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<blockquote>
<p>这样的话，在跳转成功的目标页的生命周期方法里就能通过 <code>this.$router.params</code> 获取到传入的参数，例如上述跳转，在目标页的 <code>componentWillMount</code> 生命周期里获取入参</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span> <span class="keyword">extends</span> <span class="title">Taro</span>.<span class="title">Component</span> </span>&#123;</span><br><span class="line">  componentWillMount () &#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="keyword">this</span>.$router.params) <span class="comment">// 输出 &#123; id: 2, type: 'test' &#125;</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="四、专属的方法"><a href="#四、专属的方法" class="headerlink" title="四、专属的方法"></a>四、专属的方法</h2><blockquote>
<p>在小程序中，页面还有在一些专属的方法成员，如下</p>
</blockquote>
<table>
<thead>
<tr>
<th>方法</th>
<th>作用</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>onPullDownRefresh</code></td>
<td>页面相关事件处理函数–监听用户下拉动作</td>
</tr>
<tr>
<td><code>onReachBottom</code></td>
<td>页面上拉触底事件的处理函数</td>
</tr>
<tr>
<td><code>onShareAppMessage</code></td>
<td>用户点击右上角转发</td>
</tr>
<tr>
<td><code>onPageScroll</code></td>
<td>页面滚动触发事件的处理函数</td>
</tr>
<tr>
<td><code>onTabItemTap</code></td>
<td>当前是 tab 页时，点击 <code>tab</code> 时触发</td>
</tr>
</tbody>
</table>
<blockquote>
<p>以上成员方案在 <code>Taro</code> 的页面中同样可以使用，书写同名方法即可，不过需要注意的，目前暂时只有微信小程序端支持这些方法，编译到H5端后这些方法均会失效</p>
</blockquote>
<h2 id="五、更多参考"><a href="#五、更多参考" class="headerlink" title="五、更多参考"></a>五、更多参考</h2><ul>
<li><a href="https://nervjs.github.io/taro/" target="_blank" rel="noopener">Taro文档</a></li>
<li><a href="https://taro-ui.aotu.io/#/" target="_blank" rel="noopener">Taro-UI</a></li>
<li><a href="https://baijiahao.baidu.com/s?id=1603297934363840853&amp;wfr=spider&amp;for=pc" target="_blank" rel="noopener">一文看懂，支撑京东核心业务小程序的统一开发框架「Taro」</a></li>
</ul>

      </div>
    
  </div>

</article>

<button class="assist-btn2 circle" id="assist_btn2" title="点亮屏幕" style="left: 27px; top: 152px;">
  <i class="iconfont" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>
<button class="assist-btn1 circle" id="assist_btn1" title="关闭屏幕亮度" style="left: 27px; top: 152px;">
  <i class="iconfont toc-title" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>


<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>	

<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
<script>
  const btw = new BTWPlugin();
  btw.init({
    id: "container",
    blogId: "22699-1592137983091-414",
    name: "前端进阶之旅",
    qrcode: "https://poetries1.gitee.io/img-repo/2020/06/qrcode.jpg",
    keyword: "3a3b3c",
  });
</script>

<script type="text/javascript">

// white theme
var body = {color: "#555", background: "#000"};
var a_tag = {color: "#222"};
var header = { background: "#222"};
var logo_line_i = {background: "#222"};
// var post_code = {background: "#eee", color: "#222"};

function switch_theme() {
 $("body").css(body);
 $("a:not('.links-of-author-item a, .site-state-item a, .site-state-posts a, .feed-link a, .motion-element a, .post-tags a, .show-commit-cls a, #donate_board a')").css(a_tag);
 $(".header, .footer").css(header);
 $(".logo-line-before i, .logo-line-after i").css(logo_line_i);
 //$(".post code").css(post_code);
 $("#idhyt-surprise-ball #idhyt-surprise-ball-animation .drag").css(a_tag);
 $(".post-title-link, .posts-expand .post-meta, .post-comments-count, .disqus-comment-count, .post-category a, .post-nav-next a, .post-nav-item a").css(a_tag);
 
 // $("code").css({color: '#c5c8c6', background: '#1d1f21'});
 //$("#assist_btn1").hide(1500);
}

$(function () {
$("#assist_btn2").css("display","none");
 $("#assist_btn1").click(function() {
     switch_theme();
$("div#toc.toc-article").css({
 "background":"#eaeaea",
 "opacity":1
});
$(".toc-article ol").show();
$("#toc.toc-article .toc-title").css("color","#a98602");
$("#assist_btn1").css("display","none");
$("#assist_btn2").css("display","block");
 });
$("#assist_btn2").click(function() {
$("#assist_btn2").css("display","none");
$("#assist_btn1").css("display","block");
$("body").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
     $(".header, .footer").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
$(".toc-article ol").toggle(1000);
 });
});


//背景随机

var Y, O, E, L, B, C, T, z, N, S, A, I;
!function() {
var e = function() {
for (O.clearRect(0, 0, L, B), T = [{
x: 0,
y: .7 * B + C
}, {
x: 0,
y: .7 * B - C
}]; T[1].x < L + C;) t(T[0], T[1])
}, t = function(e, t) {
O.beginPath(), O.moveTo(e.x, e.y), O.lineTo(t.x, t.y);
var n = t.x + (2 * I() - .25) * C,
 r = a(t.y);
O.lineTo(n, r), O.closePath(), N -= S / -50, O.fillStyle = "#" + (127 * A(N) + 128 << 16 | 127 * A(N + S / 3) + 128 << 8 | 127 * A(N + S / 3 * 2) + 128).toString(16), O.fill(), T[0] = T[1], T[1] = {
 x: n,
 y: r
}
}, a = function n(e) {
var t = e + (2 * I() - 1.1) * C;
return t > B || t < 0 ? n(e) : t
};
Y = document.getElementById("evanyou"), O = Y.getContext("2d"), E = window.devicePixelRatio || 1, L = window.innerWidth, B = window.innerHeight, C = 90, z = Math, N = 0, S = 2 * z.PI, A = z.cos, I = z.random, Y.width = L * E, Y.height = B * E, O.scale(E, E), O.globalAlpha = .6, document.onclick = e, document.ontouchstart = e, e()
}()

   
$("#toc-eye").click(function(){
$("#toc.toc-article").toggle(1000);
});

</script>


   
  <div class="text-center donation">
    <div class="inner-donation">
      <span class="btn-donation">支持一下</span>
      <div class="donation-body">
        <div class="tip text-center">扫一扫，支持poetries</div>
        <ul>
        
          <li class="item">
            
              <span>微信扫一扫</span>
            
            <img src="/images/weixin.jpg" alt="">
          </li>
        
          <li class="item">
            
              <span>支付宝扫一扫</span>
            
            <img src="/images/zhifubao.jpg" alt="">
          </li>
        
        </ul>
      </div>
    </div>
  </div>


   
  <div class="box-prev-next clearfix">
    <a class="show pull-left" href="/2018/08/31/acq-mobx/">
        <i class="icon icon-angle-left"></i>
    </a>
    <a class="show pull-right" href="/2018/09/04/webpack-custom-work-flow/">
        <i class="icon icon-angle-right"></i>
    </a>
  </div>




</div>


  <a id="backTop" class="back-top">
    <i class="icon-angle-up"></i>
  </a>




  <div class="modal" id="modal">
  <span id="cover" class="cover hide"></span>
  <div id="modal-dialog" class="modal-dialog hide-dialog">
    <div class="modal-header">
      <span id="close" class="btn-close">关闭</span>
    </div>
    <hr>
    <div class="modal-body">
      <ul class="list-toolbox">
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/archives/"
              rel="noopener noreferrer"
              target="_self"
              >
              博客
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/categories/"
              rel="noopener noreferrer"
              target="_self"
              >
              分类
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/tags/"
              rel="noopener noreferrer"
              target="_self"
              >
              标签
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/search/"
              rel="noopener noreferrer"
              target="_self"
              >
              搜索
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/link/"
              rel="noopener noreferrer"
              target="_self"
              >
              友链
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/about/"
              rel="noopener noreferrer"
              target="_self"
              >
              关于
            </a>
          </li>
        
      </ul>

    </div>
  </div>
</div>



  
      <div class="fexo-comments comments-post">
    

    

    
    

    

    
    

    

<!-- Gitalk评论插件通用代码 -->
<div id="gitalk-container"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script>
const gitalk = new Gitalk({
  clientID: '5567a2c4abb858009d96',
  clientSecret: 'b9039ec056cf5c2346b3cdb63308a28c163f91e5',
  repo: 'poetries.github.io',
  owner: 'poetries',
  // 在这里设置一下截取前50个字符串, 这是因为 github 对 label 的长度有了要求, 如果超过
  // 50个字符串则会报错.
  // id: location.pathname.split('/').pop().substring(0, 49),
  id: location.pathname,
  admin: ['poetries'],
  // facebook-like distraction free mode
  distractionFreeMode: false
})
gitalk.render('gitalk-container')
</script>
<!-- Gitalk代码结束 -->



  </div>

  

  <script type="text/javascript">
  function loadScript(url, callback) {
    var script = document.createElement('script')
    script.type = 'text/javascript';

    if (script.readyState) { //IE
      script.onreadystatechange = function() {
        if (script.readyState == 'loaded' ||
          script.readyState == 'complete') {
          script.onreadystatechange = null;
          callback();
        }
      };
    } else { //Others
      script.onload = function() {
        callback();
      };
    }

    script.src = url;
    document.getElementsByTagName('head')[0].appendChild(script);
  }

  window.onload = function() {
    loadScript('/js/bundle.js?235683', function() {
      // load success
    });
  }
</script>


  <!-- 页面点击小红心 -->
  <script type="text/javascript" src="/js/clicklove.js"></script>
 
  
</body>
</html>
